package com.css.fxfzypg.modules.resultsManagement.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.resultsManagement.entity.MapManagementEntity;
import com.css.fxfzypg.modules.resultsManagement.entity.MapType;
import com.css.fxfzypg.modules.resultsManagement.queryParams.MapManagementQueryParams;
import com.css.fxfzypg.modules.resultsManagement.service.MapTypeService;
import com.css.fxfzypg.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

/**
 * 图件类型管理
 */
@RestController
@RequestMapping("/mapType")
@Slf4j
public class MapTypeController {

    @Resource
    MapTypeService mapTypeService;
    // 新增
    @PostMapping("/saveMapType")
    public RestResponse saveMapType(@RequestBody MapType mapType) {
        return mapTypeService.saveMapType(mapType);
    }
     // id查询
    @GetMapping("/getById/{id}")
    public RestResponse getById(@PathVariable("id") String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(mapTypeService.getById(id));
        } catch (Exception e) {
            log.error("查询图件类型数据失败", e);
            restResponse = RestResponse.fail("查询图件类型数据失败");
        }
        return restResponse;
    }
    //删除
    @PostMapping("/deleteById/{id}")
    public RestResponse deleteById(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            mapTypeService.deleteById(id);
            restResponse = RestResponse.succeed("删除成功");
        } catch (Exception e) {
            log.error("删除图件类型数据失败");
            restResponse = RestResponse.fail("删除图件类型数据失败");
        }
        return restResponse;
    }
    //修改
    @PostMapping("/update")
    public RestResponse update(@RequestBody MapType mapType) {
        RestResponse restResponse = null;
        try {
            MapType mapType1 = mapTypeService.update(mapType);
            restResponse = RestResponse.succeed(mapType1);
        } catch (Exception e) {
            log.error("修改图件类型数据失败");
            restResponse = RestResponse.fail("修改图件类型数据失败");
        }
        return restResponse;
    }
    //分页查询
    @GetMapping("/queryMapTypes")
    public RestResponse queryMapTypes(HttpServletRequest request, MapType mapType) {
        RestResponse response = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            Map<String, Object> map = mapTypeService.queryMapTypes(mapType, curPage, pageSize);
            response = RestResponse.succeed(map);
        } catch (Exception e) {
            log.error("查询图件类型数据失败!", e);
            response = RestResponse.fail("查询图件类型数据失败!");
        }
        return response;
    }
    //图件类型不可重复接口
    @PostMapping("/checkType")
    public RestResponse checkType(@RequestBody MapType mapType) {
        return mapTypeService.checkType(mapType);
    }
    //根据报告类型查询图件
    @GetMapping("/getByReportType")
    public RestResponse getByReportType(@RequestParam String reportType) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(mapTypeService.getByReportType(reportType));
        } catch (Exception e) {
            log.error("查询图件类型数据失败", e);
            restResponse = RestResponse.fail("查询图件类型数据失败");
        }
        return restResponse;
    }
    //删除校验
    @PostMapping("/check/{id}")
    public RestResponse check(@PathVariable String id) {
        return mapTypeService.check(id);
    }
}
